#pragma once

#include "LinkEndDestructionData.h"

#include "InputPin.h"

namespace uml {

const bool LinkEndDestructionData::isDestroyDuplicates_default_ = false;
LinkEndDestructionData::LinkEndDestructionData(const QString& umlType)
    : LinkEndData(umlType) {}

void LinkEndDestructionData::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    LinkEndData::fromJson(json, errorList);
    destroyAt_ = JsonSerializable::create<InputPin>(json.value("destroyAt"), errorList);

    isDestroyDuplicates_ = json.value("isDestroyDuplicates").toBool(isDestroyDuplicates_default_);
}

void LinkEndDestructionData::toJson(QJsonObject& json) {
    LinkEndData::toJson(json);
    if (destroyAt_) {
        QJsonObject destroyAt_json;
        destroyAt_->toJson(destroyAt_json);
        json.insert("destroyAt", destroyAt_json);
    }
    if (isDestroyDuplicates_ != isDestroyDuplicates_default_) {
        json.insert("isDestroyDuplicates", isDestroyDuplicates_);
    }
}

/// <summary>
/// allPins
    /// Adds the destroyAt InputPin (if any) to the set of all Pins.
/// </summary>
    /// <code>
    /// result = (self.LinkEndData::allPins()->including(destroyAt))
    /// </code>
shared_ptr<vector<InputPin>> LinkEndDestructionData::allPins() const
{
    return nullptr;
}

/// <summary>
/// destroyAt getter
/// The InputPin that provides the position of an existing link to be destroyed in
/// an ordered, nonunique Association end. The type of the destroyAt InputPin is
/// UnlimitedNatural, but the value cannot be zero or unlimited.
/// </summary>
shared_ptr<InputPin> LinkEndDestructionData::destroyAt() const {
    return destroyAt_;
}

/// <summary>
/// destroyAt setter
/// The InputPin that provides the position of an existing link to be destroyed in
/// an ordered, nonunique Association end. The type of the destroyAt InputPin is
/// UnlimitedNatural, but the value cannot be zero or unlimited.
/// </summary>
void LinkEndDestructionData::setDestroyAt(shared_ptr<InputPin> value) {
    destroyAt_ = value;
}

/// <summary>
/// isDestroyDuplicates getter
/// Specifies whether to destroy duplicates of the value in nonunique Association
/// ends.
/// </summary>
bool LinkEndDestructionData::isDestroyDuplicates() const {
    return isDestroyDuplicates_;
}

/// <summary>
/// isDestroyDuplicates setter
/// Specifies whether to destroy duplicates of the value in nonunique Association
/// ends.
/// </summary>
void LinkEndDestructionData::setIsDestroyDuplicates(bool value) {
    isDestroyDuplicates_ = value;
}

} // namespace uml
